home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / picks / HTTrack / httrack-3.22-3.exe / {app} / src_win / WinHTTrack / InsertUrl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-24  |  5.9 KB  |  234 lines

  1. // InsertUrl.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. extern "C" {
  7.   #include "htsglobal.h"
  8.   #include "htsbase.h"
  9.   #include "htslib.h"
  10. }
  11. #include "winsock.h"
  12.  
  13. #include "Shell.h"
  14. #include "InsertUrl.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. extern HICON httrack_icon;
  23.  
  24. // Helper
  25. extern LaunchHelp* HtsHelper;
  26.  
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CInsertUrl dialog
  30.  
  31.  
  32. CInsertUrl::CInsertUrl(CWnd* pParent /*=NULL*/)
  33.     : CDialog(CInsertUrl::IDD, pParent)
  34. {
  35.     //{{AFX_DATA_INIT(CInsertUrl)
  36.     m_urllogin = _T("");
  37.     m_urlpass = _T("");
  38.     m_urladr = _T("");
  39.     //}}AFX_DATA_INIT
  40. }
  41.  
  42.  
  43. void CInsertUrl::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CDialog::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(CInsertUrl)
  47.     DDX_Text(pDX, IDC_urllogin, m_urllogin);
  48.     DDX_Text(pDX, IDC_urlpass, m_urlpass);
  49.     DDX_Text(pDX, IDC_urladr, m_urladr);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(CInsertUrl, CDialog)
  55.     //{{AFX_MSG_MAP(CInsertUrl)
  56.     ON_BN_CLICKED(ID_capt, Oncapt)
  57.     //}}AFX_MSG_MAP
  58.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  59.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  60.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  61.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CInsertUrl message handlers
  66.  
  67. BOOL CInsertUrl::OnInitDialog() 
  68. {
  69.     CDialog::OnInitDialog();
  70.   SetIcon(httrack_icon,false);
  71.   SetIcon(httrack_icon,true);
  72.   EnableToolTips(true);     // TOOL TIPS
  73.   SetForegroundWindow();   // yop en premier plan!
  74.     
  75.   if (LANG_T(-1)) {    // Patcher en franÁais
  76.     SetWindowText( LANG(LANG_T1));
  77.     SetDlgItemText(IDC_STATIC_adr,LANG(LANG_T2));
  78.     SetDlgItemText(IDC_STATIC_auth,LANG(LANG_T4));
  79.     SetDlgItemText(IDC_STATIC_login,LANG(LANG_T5));
  80.     SetDlgItemText(IDC_STATIC_pass,LANG(LANG_T6));
  81.     SetDlgItemText(IDC_STATIC_capt,LANG(LANG_T7));
  82.     SetDlgItemText(ID_capt,LANG(LANG_T8));
  83.     SetDlgItemText(IDOK,LANG(LANG_OK));
  84.     SetDlgItemText(IDCANCEL,LANG(LANG_CANCEL));
  85.   }
  86.  
  87.     return TRUE;  // return TRUE unless you set the focus to a control
  88.                   // EXCEPTION: OCX Property Pages should return FALSE
  89. }
  90.  
  91.  
  92. // ------------------------------------------------------------
  93. // TOOL TIPS
  94. //
  95. // ajouter dans le .cpp:
  96. // remplacer les deux Wid1:: par le nom de la classe::
  97. // dans la message map, ajouter
  98. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  99. // dans initdialog ajouter
  100. // EnableToolTips(true);     // TOOL TIPS
  101. //
  102. // ajouter dans le .h:
  103. // char* GetTip(int id);
  104. // et en generated message map
  105. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  106. BOOL CInsertUrl::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  107. {
  108.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  109.   UINT nID =pNMHDR->idFrom;
  110.   if (pTTT->uFlags & TTF_IDISHWND)
  111.   {
  112.     // idFrom is actually the HWND of the tool
  113.     nID = ::GetDlgCtrlID((HWND)nID);
  114.     if(nID)
  115.     {
  116.       char* st=GetTip(nID);
  117.       if (st != "") {
  118.         pTTT->lpszText = st;
  119.         pTTT->hinst = AfxGetResourceHandle();
  120.         return(TRUE);
  121.       }
  122.     }
  123.   }
  124.   return(FALSE);
  125. }
  126. char* CInsertUrl::GetTip(int ID)
  127. {
  128.   switch(ID) {
  129.     case IDC_urladr:    return LANG(LANG_T10); break;
  130.     case IDC_urllogin:  return LANG(LANG_T12); break;
  131.     case IDC_urlpass:   return LANG(LANG_T13); break;
  132.     case ID_capt:       return LANG(LANG_T14); break;
  133.     case IDOK:           return LANG(LANG_TIPOK); break;      
  134.     case IDCANCEL:       return LANG(LANG_TIPCANCEL); break;
  135.     //case : return ""; break;
  136.   }
  137.   return "";
  138. }
  139. // TOOL TIPS
  140. // ------------------------------------------------------------
  141.  
  142. // Appel aide
  143. BOOL CInsertUrl::OnHelpInfo2() {
  144.   return OnHelpInfo(NULL);
  145. }
  146.  
  147. BOOL CInsertUrl::OnHelpInfo(HELPINFO* dummy) 
  148. {
  149.   HtsHelper->Help();
  150.   return true;
  151. }
  152.  
  153. // Ne fait pas partie de la classe
  154. UINT RunBackCatchServer( LPVOID pP ) {
  155.   CInsertUrl* _this=(CInsertUrl*) pP;
  156.   //
  157.   char url[HTS_URLMAXSIZE*2]; url[0]='\0';
  158.   char method[32]; method[0]='\0';
  159.   char data[32768]; data[0]='\0';
  160.   if (catch_url(_this->soc,url,method,data)) {
  161.     if (_this->m_hWnd) {
  162.       char dest[HTS_URLMAXSIZE*2];
  163.       int i=0;
  164.       strcpybuff(dest,_this->dest_path);
  165.       {
  166.         char* a;
  167.         while(a=strchr(dest,'\\')) *a='/';
  168.         structcheck(dest);
  169.       }
  170.       do {
  171.         sprintf(dest,"%s%s%d",_this->dest_path,"hts-post",i);
  172.         i++;
  173.       } while(fexist(dest));
  174.       {
  175.         FILE* fp=fopen(dest,"wb");
  176.         if (fp) {
  177.           fwrite(data,strlen(data),1,fp);
  178.           fclose(fp);
  179.         }
  180.       }
  181.       // former URL!
  182.       {
  183.         char finalurl[HTS_URLMAXSIZE*2];
  184.         escape_check_url(dest);
  185.         sprintf(finalurl,"%s"POSTTOK"file:%s",url,dest);
  186.         _this->SetDlgItemText(IDC_urladr,finalurl);
  187.       }
  188.     }
  189.   } else {
  190.     CString info;
  191.     info.Format("Error while capturing URL\n(from %s)",url);
  192.     AfxMessageBox(info);
  193.   }
  194. #ifdef _WIN32
  195.   closesocket(_this->soc);
  196. #else
  197.   close(_this->soc);
  198. #endif
  199.   // Quitter
  200.   if (_this->m_hWnd) {
  201.     if (_this->dial.m_hWnd) {
  202.       ::SendMessage(_this->dial.m_hWnd,WM_CLOSE,0,0);
  203.     }
  204.   }
  205.   //_this->dial.EndDialog(IDOK);
  206.   return 0;
  207. }
  208.  
  209. void CInsertUrl::Oncapt() 
  210. {
  211.   // Demander un port d'Ècoute
  212.   adr_prox[0]='\0';
  213.   port_prox=0;
  214.   soc=catch_url_init_std(&port_prox,adr_prox);
  215.   if (soc != INVALID_SOCKET) {
  216.     //
  217.     char s[8192];
  218.     sprintf(s,"Please TEMPORARILY set your browser's proxy preferences to:\r\n\r\nProxy's address:\r\n%s\r\nProxy's port:\r\n%d\r\n",adr_prox,port_prox);
  219.     //
  220.     dial.m_info=s;
  221.     // ECOUTER EN THREAD
  222.     AfxBeginThread(RunBackCatchServer,this);
  223.     // AFFICHER INFOS
  224.     {
  225.       CWaitCursor wait;      // Afficher curseur sablier
  226.       if (dial.DoModal() != IDOK) {
  227.       }
  228.     }
  229.     //
  230.   } else
  231.     AfxMessageBox("Error!..",MB_SYSTEMMODAL);
  232. }
  233.  
  234.